﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;

namespace Reborn_WorldServer
{
    public class ServerSocketData
    {
        public Socket socket;
        public byte[] dataBuffer = new byte[1024];

        public ServerSocketData(Socket serverSocket)
        {
            socket = serverSocket;
        }

        private string incomingMessages = "";
        public void AppendData(string e)
        {
            lock (messageLock)
            {
                incomingMessages = incomingMessages + e;
            }
        }

        public string getRawData()
        {
            return incomingMessages;
        }

        private object messageLock = new object();
        public string getMessage()
        {
            lock (messageLock)
            {
                if (incomingMessages.IndexOf("\0") > -1)
                {
                    string message = incomingMessages.Substring(0, incomingMessages.IndexOf("\0"));
                    incomingMessages = incomingMessages.Substring(incomingMessages.IndexOf("\0") + 1);
                    return message;
                }
                else
                    return "";
            }
        }
    }
}
